import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    meta:{
      title:'首页'
    },
    component: ()=>import('../views/Home.vue')
  },
  {
    path: '/Brandhome',
    name: 'BrandHome',
    meta:{
      title:'品牌首页'
    },
    component: ()=>import('../views/Brand-home.vue')
  },
  {
    path: '/login',
    name: 'Login',
    meta:{
      title:'登录'
    },
    component: ()=>import('../views/Login.vue')
  },
  {
    path: '/password',
    name: 'ChangePassword',
    meta:{
      title:'修改密码'
    },
    component: ()=>import('../views/Change-password.vue')
  },
  {
    path: '/pretty',
    name: 'PrettyManGirl',
    meta:{
      title:'优男靓女'
    },
    component: ()=>import('../views/Pretty-man-girl.vue')
  },
  {
    path: '/prettylist',
    name: 'PrettyManGirlList',
    meta:{
      title:'优男靓女'
    },
    component: ()=>import('../views/Pretty-man-girl-more.vue')
  },
  {
    path: '/fellowship',
    name: 'OrganizeFellowship',
    meta:{
      title:'组织联谊'
    },
    component: ()=>import('../views/Organize-fellowship.vue')
  },
  {
    path: '/Gagslist',
    name: 'GagsList',
    meta:{
      title:'精彩花絮'
    },
    component: ()=>import('../views/Gags-more.vue')
  },
  {
    path: '/Gagsdetail',
    name: 'GagsDetail',
    meta:{
      title:'精彩花絮'
    },
    component: ()=>import('../views/Gags-detail.vue')
  },
  {
    path: '/Fellowshipdetail',
    name: 'FellowshipDetail',
    meta:{
      title:'联谊详情'
    },
    component: ()=>import('../views/Fellowship-detail.vue')
  },
  {
    path: '/Activitymore',
    name: 'ActivityMore',
    meta:{
      title:'活动报名'
    },
    component: ()=>import('../views/Activity-more.vue')
  },
  {
    path: '/Activitydetail',
    name: 'ActivityDetail',
    meta:{
      title:'活动详情'
    },
    component: ()=>import('../views/Activity-detail.vue')
  },
  {
    path: '/Brandmore',
    name: 'BrandMore',
    meta:{
      title:'交友品牌'
    },
    component: ()=>import('../views/Brand-more.vue')
  },
  {
    path: '/about',
    name: 'About',
    meta:{
      title:'我的'
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/Myactivity',
    name: 'MyActivity',
    meta:{
      title:'我的活动'
    },
    component: ()=>import('../views/My-activity.vue')
  },
  {
    path: '/isLogin',
    name: 'isLogin',
    meta:{
      title:'免登接口'
    },
    component: ()=>import('../views/hzszqtLogin.vue')
  },
  {
    path: '/Mybrand',
    name: 'MyBrand',
    meta:{
      title:'我的品牌'
    },
    component: ()=>import('../views/My-brand.vue')
  },
  {
    path: '/Mygroup',
    name: 'MyGroup',
    meta:{
      title:'我发起的组团'
    },
    component: ()=>import('../views/My-group.vue')
  },
  {
    path: '/Messageboard',
    name: 'MessageBoard',
    meta:{
      title:'留言板'
    },
    component: ()=>import('../views/Message-board.vue')
  },
  {
    path: '/Joinbrand',
    name: 'JoinBrand',
    meta:{
      title:'申请加入品牌'
    },
    component: ()=>import('../views/Join-brand.vue')
  },
  {
    path: '/Applicantinformation',
    name: 'ApplicantInformation',
    meta:{
      title:'报名人员信息'
    },
    component: ()=>import('../views/Applicant-information.vue')
  },
  {
    path: '/Personaldata',
    name: 'PersonalData',
    meta:{
      title:'个人资料'
    },
    component: ()=>import('../views/Personal-data.vue')
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('jyToken')
  if (!token && to.name !== 'Login') {
    next({ name:'Login', replace: true })
  } else if (token) {
    if(to.name === 'Login'){
      next({ name:'Home' })
    }else{
      next()
    }
  } else {
    next()
  }
})

export default router
